package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.dto.ProductHotSaleDTO;
import com.sc.nft.enums.ProductTypeEnum;
import com.sc.nft.enums.task.ActivityTypeEnum;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.MallHotSaleActivity;
import com.sc.nft.mapper.MallHotSaleActivityMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

/**
 * 热卖商品(sc_mall_hot_sale_activity)数据DAO
 *
 * @author Sun
 * @since 2023-09-02 16:28:37
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class MallHotSaleActivityDao extends ServiceImpl<MallHotSaleActivityMapper, MallHotSaleActivity> {

    public IPage<ProductHotSaleDTO> getHotSalePage(ActivityTypeEnum activityType, ProductTypeEnum type, Boolean status, Long daoId, String name, Page page) {
        return baseMapper.getHotSalePage(page,activityType!=null?activityType.getCode():null, type!=null?type.getCode():null, status, daoId, name);
    }

    public MallHotSaleActivity getActivityId(Long activityId) {
        LambdaQueryWrapper<MallHotSaleActivity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(MallHotSaleActivity::getActivityId,activityId);
        return getOne(wrapper);
    }

    public boolean updateStatusByActivityId(Long activityId,Boolean status) {
        LambdaUpdateWrapper<MallHotSaleActivity> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(MallHotSaleActivity::getActivityId, activityId);
        wrapper.set(MallHotSaleActivity::getStatus, status);
        return update(wrapper);
    }
}